package parking.naimi_trehel;

import java.io.Serializable;

/**
 * @author Sophie and Ronnie
 * Description : Class representing the token used by Naimi Trehel algorithm
 *				 The token possesses the number of spots available in the parking
 * @date 9 November 2013
 */
public class Token implements Serializable {

	private static final long serialVersionUID = 8707833347593802979L;
	private int spots;
	private int spotsAtStart;
	
	/**
	 * Constructor method
	 * @param spots represents the number of spots of the parking
	 */
	public Token(int spots) {
		this.setSpots(spots);
		this.setSpotsAtStart(spots);
	}

	/**
	 * Get the number of actual available spots
	 * @return The current number of spots
	 */
	public int getSpots() {
		return spots;
	}

	/**
	 * Fix the number of spots
	 * @param spots The number of spots wished
	 */
	public void setSpots(int spots) {
		this.spots = spots;
	}
	
	/**
	 * Increase the number of current spots in the parking
	 */
	public void incSpots() {
		if (this.spots < this.spotsAtStart) {
			this.spots++;
		}
	}
	
	/**
	 * Decrease the number of current spots in the parking if the
	 * latter is more than 0
	 */
	public void decSpots() {
		if (this.spots > 0)
			this.spots--;
	}

	/**
	 * Used for debugging process
	 * @return current number of spots at instantiation process of this class 
	 */
	public int getSpotsAtStart() {
		return spotsAtStart;
	}

	/**
	 * Used for debugging process
	 * @param spotsAtStart is initialized as the same number of spots at the initialization
	 * of this class with the number of spots available in the parking
	 */
	public void setSpotsAtStart(int spotsAtStart) {
		this.spotsAtStart = spotsAtStart;
	}
}
